package Algorithm.ReviewCode;

public class LinkedListDummyHeadDelete {

    public static ListNode removeElements(ListNode head, int val) {

        ListNode dummyHead = new ListNode(-1);
        dummyHead.next = head;

        ListNode cur = dummyHead;
        while (cur.next != null){
            if (cur.next.val == val) {
                cur.next = cur.next.next;
            }else {
                cur = cur.next;
            }
        }
        return dummyHead.next;      //这里不能用head，否则删不到头节点
    }

    public static void main(String[] args) {
        int[] a = new int[]{1,2,3,4,2,5};
        ListNode listNode = new ListNode(a);
        System.out.println(listNode);
        ListNode listNode1 = removeElements(listNode,1);
        System.out.println(listNode1);

    }
}
